/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package blue.dao;

import blue.dto.Accounts;
import blue.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author CUTE
 */
public class AccountsDAO {

    private static Logger logger = Logger.getLogger(AccountsDAO.class.getName());
    //C:Create
    private final String createAccounts = "insert into accounts (username,password,role_id,firstname,lastname,bithday,email,mobiel,phone,address) values(?,?,?,?,?,?,?,?,?,?)";
  

    public  Accounts create(Accounts acounts) {
        Connection con = null;
        try {
            PreparedStatement ptmt = null;
            con = DBUtil.getConnection();

            ptmt = con.prepareStatement(createAccounts);
            ptmt.setString(1, acounts.getUsername());
            ptmt.setString(2, acounts.getPassword());
            ptmt.setInt(3, acounts.getRole_id());
            ptmt.setString(4, acounts.getFirstname());
            ptmt.setString(5, acounts.getLastname());
            ptmt.setDate(6, acounts.getBirthday());
            ptmt.setString(7, acounts.getEmail());
            ptmt.setDouble(8, acounts.getMobile());
            ptmt.setDouble(9, acounts.getPhone());
            ptmt.setDate(10, acounts.getDateupdate());

            ptmt.executeUpdate();
            ptmt.close();
            return acounts;
        } catch (SQLException ex) {
            logger.log(Level.SEVERE, null, ex);
            return null;
        } finally {
            DBUtil.closeConnection(con);
        }
    }
}
